import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/showRequest")
public class ShowRequest extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        StringBuffer result = new StringBuffer();

        //协议  HTTP/1.1
        result.append(req.getProtocol());
//        result.append("\n");
        result.append("<br>");

        //请求的方法  GET
        result.append(req.getMethod());
//        result.append("\n");
        result.append("<br>");

        //请求的路径 资源定位 /hello_servlet/showRequest
        result.append(req.getRequestURI());
//        result.append("\n");
        result.append("<br>");

        result.append(req.getQueryString());
//        result.append("\n");
        result.append("<br>");

        // /hello_servlet
        result.append(req.getContextPath());

        // 在响应中设置上 body 的类型，方便浏览器进行解析
        resp.setContentType("text/html;charset=utf8");

        resp.getWriter().write(result.toString());
    }
}
